var express=require("express");
var router=express.Router();
var multer=require("multer");
var fs=require("fs");
var array=[];

var upload=multer(
  {
    dest:"upload",
    limits:{fileSize:1024*1024*1024*15}
  }
);

var single=upload.single("myfile");
var arr=upload.array("myfiles",2);
var fields=upload.fields([{
  name:"f1",maxCount:1
},{name:"f2",maxCount:2}]);

router.get("/",function (req,res){
  res.locals.list=array;
  res.render("album");
});



router.post("/test/upload",single,function (req,res){
  res.send(req.file);
});

router.post("/test/upload2",arr,function (req,res){
  res.send(req.files);
});

router.post("/test/upload3",fields,function (req,res){
  res.send(req.files);
});

router.post("/upload4",arr,function (req,res){
  array.push(req.files);
  res.redirect("back");
});

router.get("/up/:filename",function (req,res){
    var rs=fs.createReadStream("upload/"+req.params.filename);
      rs.pipe(res);
});
module.exports=router;
